home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / ole2book.zip / CHAP11.ZIP / CHAP11 / HSCHMOO / IADVSINK.CPP < prev    next >
C/C++ Source or Header  |  1993-06-13  |  4KB  |  172 lines

  1. /*
  2.  * IADVSINK.CPP
  3.  *
  4.  * Implementation of the IAdviseSink interface for the Schmoo Handler
  5.  * such that it will be notified when data is modified in the server.
  6.  *
  7.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Software Design Engineer
  10.  * Microsoft Systems Developer Relations
  11.  *
  12.  * Internet  :  kraigb@microsoft.com
  13.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  14.  */
  15.  
  16.  
  17. #include "hschmoo.h"
  18.  
  19.  
  20. /*
  21.  * CImpIAdviseSink::CImpIAdviseSink
  22.  * CImpIAdviseSink::~CImpIAdviseSink
  23.  *
  24.  * Parameters (Constructor):
  25.  *  pObj            LPCFigure of the object we're in.
  26.  *  punkOuter       LPUNKNOWN to which we delegate.
  27.  */
  28.  
  29. CImpIAdviseSink::CImpIAdviseSink(LPCFigure pObj, LPUNKNOWN punkOuter)
  30.     {
  31.     m_cRef=0;
  32.     m_pObj=pObj;
  33.     m_punkOuter=punkOuter;
  34.     return;
  35.     }
  36.  
  37. CImpIAdviseSink::~CImpIAdviseSink(void)
  38.     {
  39.     return;
  40.     }
  41.  
  42.  
  43.  
  44.  
  45. /*
  46.  * CImpIAdviseSink::QueryInterface
  47.  * CImpIAdviseSink::AddRef
  48.  * CImpIAdviseSink::Release
  49.  *
  50.  * Purpose:
  51.  *  IUnknown members for CImpIAdviseSink object.
  52.  */
  53.  
  54. STDMETHODIMP CImpIAdviseSink::QueryInterface(REFIID riid, LPVOID FAR *ppv)
  55.     {
  56.     /*
  57.      * For some reason or another, your IAdviseSink's QueryInterface
  58.      * has to be separate from the rest of the handler's object.  We
  59.      * can still pass on AddRefs and Releases without a big deal, since
  60.      * we're controlled by the outer object's lifetime anyway.
  61.      */
  62.     if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IAdviseSink))
  63.         {
  64.         *ppv=(LPVOID)this;
  65.         AddRef();
  66.         return NOERROR;
  67.         }
  68.  
  69.     return ResultFromScode(E_NOINTERFACE);
  70.     }
  71.  
  72.  
  73. STDMETHODIMP_(ULONG) CImpIAdviseSink::AddRef(void)
  74.     {
  75.     ++m_cRef;
  76.     return m_punkOuter->AddRef();
  77.     }
  78.  
  79. STDMETHODIMP_(ULONG) CImpIAdviseSink::Release(void)
  80.     {
  81.     --m_cRef;
  82.     return m_punkOuter->Release();
  83.     }
  84.  
  85.  
  86.  
  87.  
  88. /*
  89.  * IAdviseSink::OnViewChange
  90.  *
  91.  * Purpose:
  92.  *  We don't do anything here because we generate OnViewChange for the
  93.  *  container inside OnDataChange.  The problem is that OnViewChange will
  94.  *  come before OnDataChnage, so if we called the container's OnViewChange
  95.  *  here it would turn around and call our IViewObject::Draw which would
  96.  *  draw with outdated data.  Therefore we ignore this notification and
  97.  *  wait for OnDataChange, since that implies a view change as well.  Then
  98.  *  we can retrieve the new data first, then send OnViewChange to the
  99.  *  container such that we'll repaint with the new data.
  100.  */
  101.  
  102. STDMETHODIMP_(void) CImpIAdviseSink::OnViewChange(DWORD dwAspect, LONG lindex)
  103.     {
  104.     return;
  105.     }
  106.  
  107.  
  108.  
  109. /*
  110.  * IAdviseSink::OnDataChange
  111.  *
  112.  * Purpose:
  113.  *  Tells us that things changed in the server.  We asked for data
  114.  *  on the advise so we can copy it from here into our own structure
  115.  *  such that on the next OnViewChange we can repaint with it.
  116.  */
  117.  
  118. STDMETHODIMP_(void) CImpIAdviseSink::OnDataChange(LPFORMATETC pFE
  119.     , LPSTGMEDIUM pSTM)
  120.     {
  121.     //Get the new data first, then notify the container to repaint.
  122.     if ((pFE->cfFormat==m_pObj->m_cf) && (TYMED_HGLOBAL & pSTM->tymed))
  123.         {
  124.         LPPOLYLINEDATA      ppl;
  125.  
  126.         ppl=(LPPOLYLINEDATA)GlobalLock(pSTM->hGlobal);
  127.         _fmemcpy(&m_pObj->m_pl, ppl, CBPOLYLINEDATA);
  128.         GlobalUnlock(pSTM->hGlobal);
  129.  
  130.         /*
  131.          * Now tell the container that the view changed, but only
  132.          * if the view is not frozen.'
  133.          */
  134.         if (pFE->dwAspect & m_pObj->m_dwAdviseAspects
  135.             && !(pFE->dwAspect & m_pObj->m_dwFrozenAspects))
  136.             {
  137.             //Pass this on to the container.
  138.             if (NULL!=m_pObj->m_pIAdvSinkView)
  139.                 {
  140.                 m_pObj->m_pIAdvSinkView->OnViewChange(pFE->dwAspect
  141.                     , pFE->lindex);
  142.                 }
  143.             }
  144.         }
  145.  
  146.     return;
  147.     }
  148.  
  149.  
  150.  
  151. /*
  152.  * All others are uninteresting because if the container wants these
  153.  * it will have called IOleObject::Advise which we passed on through to
  154.  * the default handler.  IViewObject::SetAdvise is the only one we
  155.  * override.
  156.  */
  157.  
  158. STDMETHODIMP_(void) CImpIAdviseSink::OnRename(LPMONIKER pmk)
  159.     {
  160.     return;
  161.     }
  162.  
  163. STDMETHODIMP_(void) CImpIAdviseSink::OnSave(void)
  164.     {
  165.     return;
  166.     }
  167.  
  168. STDMETHODIMP_(void) CImpIAdviseSink::OnClose(void)
  169.     {
  170.     return;
  171.     }
  172.